﻿/*
*
*   $Id: script_uploadcv.js 2010-09-25 stainboy $
*
*/

var extensions = 'htm,html,doc,docx,xml,pdf,txt,rtf,odt,mht';
var attachcv = $('attachcv');
var attachname = $('attachname');
var attachpreview = $('attachpreview');
var attachext = $('attachext');

attachcv.onchange = function () { insertAttach() };

function insertAttach() {
    var path = attachcv.value;
    var ext = getExt(path);
    var re = new RegExp("(^|\\s|,)" + ext + "($|\\s|,)", "ig");

    if (path == '') {
        clearAttach();
        return;
    }
    if (extensions != '' && (re.exec(extensions) == null || ext == '')) {
        alert('对不起，简历上传仅支持如下格式的文件：' + extensions);
        clearAttach();
        return;
    }


    var localfile = attachcv.value.substr(attachcv.value.replace(/\\/g, '/').lastIndexOf('/') + 1);
    var filename = localfile.substr(0, localfile.length - ext.length - 1);

    attachname.value = filename;
    attachext.value = ext;
    attachpreview.src = "image/cv/" + ext + ".gif";
    attachpreview.parentNode.parentNode.style.display = '';
}

function clearAttach() {
    attachcv.value = null;
    attachext.value = '';
    attachname.value = '';
    attachpreview.parentNode.parentNode.style.display = 'none';
}